<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选择医生床位</title>
	<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
	<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">
	
	<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>
<body>
	<script type="text/javascript">
		$(function(){
				//显示全部待选择病人
				$("#xswdbr").linkbutton({onClick:function(){
					$("#tb-wdbr").datagrid({
					
	    			url: '', 
	    			method: 'get'
	    			});
				}});
				//查看病人信息
				$("#ckbr").linkbutton({onClick:function(){
					var rows = $("#tb-wdbr").datagrid("getSelections");
					if(rows.length == 1){
						$("#his_wdbrxx").window("open");
						var brNo = rows[0].brNo;
						$.getJSON("brxx", {"brNo": brNo}, function(data){
							$("#form-wdbrxx").form("load", data);
						});
					}
					else{
						$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
					}
					
					$('#"form-wdbrxx"').form("clear");
					
				}});
		
				//查看病人信息
				$("#kcf").linkbutton({onClick:function(){
					var rows = $("#tb-wdbr").datagrid("getSelections");
					if(rows.length == 1){
						$("#his_cfd").window("open");
						
					}
					else{
						$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
					}
				}});
				//更改病人情况
				$("#ggbrqk").linkbutton({onClick:function(){
					var rows = $("#tb-wdbr").datagrid("getSelections");
					if(rows.length == 1){
						$("#his_brqk").window("open");

						$("#tjbrqk").linkbutton({onClick:function(){
							var brNo = rows[0].brNo;
							var brSituation = document.getElementById("brqk").value;
							
							if(brSituation!='出院'&&brSituation!=''){
							$.getJSON("ggbrqk", {"brNo":brNo,"brSituation":brSituation}, function(data){
								$.messager.alert("提示", data.reason);
							});
							$("#his_brqk").window("close");
							$("#tb-wdbr").datagrid("reload");
							$("#brqk").textbox("clear");
							}
							else{
								$.messager.alert("提示", "医生不能更改病人情况为出院或者为空!");
							}
						}});
					}
					else{
						$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
					}
				}});
				
				
				
		});
	</script>

	<!--我的病人-->
	<table id="tb-wdbr" class="easyui-datagrid" 
		data-options="url:'selectysbr?zyysno=4',
			fitColumns:true,fit:true,
			pagination: true,
			pageSize: 5,
			pageList: [5, 10, 15, 20],
			rownumbers: true,
			singleSelect:true,
			
			toolbar: '#wdbrgjl'
			">
		<thead>
			<tr>
				<th data-options="field:'brNo',width:'3%', checkbox: true">病人号</th>
				<th data-options="field:'brName', align:'center', width:'15%'">病人姓名</th>
				<th data-options="field:'brSituation', align:'center', width:'15%'">病人情况</th>
				<th data-options="field:'ylkNo', align:'center', width:'15%'">医疗卡号</th>
				<th data-options="field:'ksmc',align:'center',width:'15%'">科室</th>
				<th data-options="field:'bqNo',align:'center',width:'5%'">科室号</th>
			</tr>
		</thead>
	</table>
	
	<!--工具栏-->
	<div id="wdbrgjl">
		<a  id="xswdbr" class="easyui-linkbutton" data-options="iconCls:'icon-xsqb',plain:true">显示所有病人</a>
		<a  id="ckbr" class="easyui-linkbutton" data-options="iconCls:'icon-ck',plain:true">查看病人信息</a>
		<a  id="kcf" class="easyui-linkbutton" data-options="iconCls:'icon-bc',plain:true">开处方</a>
		<a  id="ggbrqk" class="easyui-linkbutton" data-options="iconCls:'icon-bc',plain:true">更改病人情况</a>
		
		
		
		<input  id="cy-so" class="easyui-searchbox" data-options="prompt:'请输入',menu:'#cy',searcher:doSearch" style="width:300px"></input>

		<div id="cy" >
		<div data-options="name:'xm'">姓名</div>
		<div data-options="name:'ylkNo'">医疗卡号</div>
	</div>
	</div>
	<!--姓名、医疗卡的搜索栏-->
	<script>
		var url ;
		$(function(){
			doSearch();
			$("#cy").menu({
				onClick:function(itme){
					url =	(itme.name == 'xm' ? '' : '');	
					
				}
			});
		})
		function doSearch(value,name){
			$('#cy-so').searchbox({
			    searcher:function(value,name){
			    	$("#tb-wdbrtz").datagrid({
			    		url:url, 
			    		method: 'post', 
			    		queryParams: {
			    			ss: value
			    		}});
			    }
			});
			
		}
	</script>
	
	<!--我的病人信息-->
	<div id="his_wdbrxx" class="easyui-window" title="查看病人信息"  data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-xx',closed: true" 
				style="width:300px;height:370px;padding:5px;">
				<form id="form-wdbrxx" action="" method="post" >
					<div class="item"><input name="brName"   readonly="readonly"  class="easyui-textbox" data-options="label: '病人姓名：', width: 200"></div>
					<div class="item"><input name="brAge" readonly="readonly"  class="easyui-textbox" data-options="label: '年龄：', width: 200"></div>
					<div class="item"><input name="brSex" readonly="readonly" class="easyui-textbox" data-options="label: '性别：', width: 200"></div>
					<div class="item"><input name="brTel" readonly="readonly" class="easyui-textbox" data-options="label: '联系方式：', width: 200"></div>
					<div class="item"><input name="brAddress" readonly="readonly" class="easyui-textbox" data-options="label: '家庭住址：', width: 230"></div>
					<div class="item"><input name="brIdnumber" readonly="readonly" class="easyui-textbox" data-options="label: '身份证号：', width: 230"></div>
					<div class="item"><input name="ylkNo" readonly="readonly" class="easyui-textbox" data-options="label: '医疗卡号', width: 200"></div>
					<div class="item"><input name="ksmc" readonly="readonly" class="easyui-textbox " data-options="label: '科室：', width: 200"></div>
					<div class="item"><input name="brSituation" readonly="readonly" class="easyui-textbox" data-options="label: '病人情况：', width: 200"></div>
					<div class="item"><input name="cwNo" readonly="readonly" class="easyui-textbox" data-options="label: '床位', width: 200"></div>
					<div class="item"><input name="zyysNo" readonly="readonly" class="easyui-textbox" data-options="label: '住院医生', width: 200"></div>
					<div class="item"><input name="brDate" readonly="readonly" class="easyui-textbox" data-options="label: '入院时间：', width: 200"></div>
				</form>
			
	</div>
	<div id="his_brqk" class="easyui-window" title="更改病人情况"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-xx',closed: true"
		style="width: 230px; height: 110px; padding: 5px;">

		<div>
			
				<input name="brSituation" id="brqk"  class="easyui-textbox" data-options="label: '病人情况：', width: 200">
			
		</div>

		<div style="margin-top:5px;margin-right:5px;">
			<a  id="tjbrqk" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" style="float:right" >确定</a>
		</div>

	</div>
	
	
	
	
	
	<!--药品的添加script-->
	<script type="text/javascript">
		var editIndex = undefined;
		//结束正在编辑的行
		function endEditing() {
			if (editIndex == undefined) {
				return true
			}
			if ($('#yp').datagrid('validateRow', editIndex)) {
				$('#yp').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {

				return false;
			}
		}
		//事件：单击单元格的事件
		function onClickCell(index, field) {
			if (editIndex != index) {
				if (endEditing()) {
					$('#yp').datagrid('selectRow', index).datagrid('beginEdit',
							index);
					var ed = $('#yp').datagrid('getEditor', {
						index : index,
						field : field
					});
					if (ed) {
						($(ed.target).data('textbox') ? $(ed.target).textbox(
								'textbox') : $(ed.target)).focus();
					}
					editIndex = index;
				} else {
					setTimeout(function() {
						$('#yp').datagrid('selectRow', editIndex);
					}, 0);
				}
			}
		}

		//结束编辑，同步数据
		function onEndEdit(index, row) {
			var ed = $(this).datagrid('getEditor', {
				//field: 'hisclin.ypcsjgNo'
			});
			//row['hisclin.ypcsjgNo'] = $(ed.target).combogrid('getText');
		}

		//添加行
		function append() {
			if (endEditing()) {
				$('#yp').datagrid('appendRow', {
					'hisclin.ypcsjgNo' : [],
					'ypmc' : [],
					'hisclin.zlNum' : [],
				});
				editIndex = $('#yp').datagrid('getRows').length - 1;
				$('#yp').datagrid('selectRow', editIndex).datagrid('beginEdit',
						editIndex);
			}
		}

		//删除行
		function removeit() {
			if (editIndex == undefined) {
				return
			}
			$('#yp').datagrid('cancelEdit', editIndex).datagrid('deleteRow',
					editIndex);
			editIndex = undefined;
		}

		//应用
		function accept() {
			if (endEditing()) {
				endEditing();
			}
		}

		//撤消
		function reject() {
			$('#yp').datagrid('rejectChanges');
			editIndex = undefined;
		}

		//获取数据
		function getChanges() {
			var rows = $('#yp').datagrid('getChanges');
			alert(rows.length + ' rows are changed!');
		}

		//提交采购计划
		function savePlan() {
			//将datagrid中的数据行保存到隐式表单域中
			//1、获取新增的数据行
			var rows = $('#yp').datagrid('getChanges');
			console.log(JSON.stringify(rows));

			//为每一行生成对应的隐藏表单域

			for (var i = 0; i < rows.length; i++) {
				generateHidden(rows[i], "ypcsjgNo", i);
				generateHidden(rows[i], "zlNum", i);
			}

			var ff_plan = $("#k_cfmx");
			//提交表单
			ff_plan.form("submit", {
				success : function(v) {
					$.messager.alert('提示', "提交成功");
					$(":hidden[x='y']").remove();
				}
			
			});
			$("#his_cfd").window("close");
		}

		function generateHidden(row, name, i) {
			//details.planDetail
			var ff_plan = $("#k_cfmx");
			$("<input type='hidden' x='y'>").attr("name",
					"hisclin[" + i + '].' + name).val(
					row['hisclin.' + name]).appendTo(ff_plan);
		}
		
		
	</script>

	<!-- 开处方-->
	<div id="his_cfd" class="easyui-window" title="开处方"
		data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-xx',closed: true"
		style="width: 500px; height: 600px; padding: 5px;">

		<div>
			<form id="k_cfmx" action="insertzycf" method="post">
				<table>
					<tr>
						<td><input class="easyui-textbox" name="hishosp.zyysNo"data-options="label:'医生编号', width:'100%'" /></td>
						<td><input class="easyui-textbox" name="zyysxm"data-options="label:'医生名称', width:'100%'" /></td>
					</tr>
					<tr>
						<td><input class="easyui-textbox" name="hishosp.brNo"data-options="label:'病人号', width:'100%'"></td>
						<td><input class="easyui-textbox" name="hishosp.zycfDoctor"data-options="label:'医嘱', width:'100%'"></td>
					</tr>
				</table>
				<div>
					<div id="cgmx" class="easyui-tabs"
						style="width: 100%; margin-top: 10px;"
						data-options="plain:true,narrow:true">
						<div title="药品表" style="padding: 10px">
							<table id="yp" class="easyui-datagrid" style="height: auto"
								data-options="
								iconCls: 'icon-edit',
								singleSelect: true,
								toolbar: '#tb',
								method: 'get',
								onClickCell: onClickCell,
								onEndEdit: onEndEdit,
								width: '100%'
							">
								<thead>
									<tr>	
										<th data-options="field:'hisclin.ypcsjgNo',width:'40%',editor:{
										type:'combogrid',
										options:{
											url:'selectdrug',
          									idField:'cpNo',
											textField:'cpName',
											panelHeight: 'auto',
											width: '100%',
          									columns: [[
                            				{field:  'cpNo',title: '药品编号',width: 100}, 
                            				{field:  'cpName',title: '药品名称',width: 80}, 
                            				{field:  'cpType',title: '药品类型',width: 80} 
                            				]],
										}
									}">药品名称</th>	
									<th data-options="field:'ypmc',width:'40%',editor:{
										type:'combogrid',
										options:{
											url:'selectdrug',
          									idField:'cpName',
											textField:'cpName',
											panelHeight: 'auto',
											width: '',
          									columns: [[
                            				{field:  'cpNo',title: '药品编号',width: 100}, 
                            				{field:  'cpName',title: '药品名称',width: 80}, 
                            				{field:  'cpType',title: '药品类型',width: 80} 
                            				]],
										}
									}">药品名称</th>								
										<th data-options="field:'hisclin.zlNum',width:'10%',align:'center',editor:'textbox'">数量</th>
									</tr>
								</thead>
							</table>

							<div id="tb" style="height: auto">
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-add',plain:true" onclick="append()">添加一行</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-remove',plain:true"
									onclick="removeit()">移除一行</a> <a href="javascript:void(0)"
									class="easyui-linkbutton"
									data-options="iconCls:'icon-ok',plain:true" onclick="accept()">应用</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-undo',plain:true"
									onclick="reject()">撤销</a>
							</div>
						</div>
					</div>
			</form>
		</div>

		<div style="margin-top: 10px;">
			<a class="easyui-linkbutton"
				data-options="iconCls:'icon-ok', onClick: savePlan">提交处方</a>
		</div>

	</div>




</body>
</html>